//	ID : pallab81
// 	PROG : 10820
// 	LANG : C++
// 	2011-06-16-20.34.52 Thursday
//
// 	"I have not failed, I have just found 10000 ways that won't work.
//


#include <iostream>
#include <algorithm>
#include <vector>
#include <sstream>
#include <fstream>
#include <string>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>

#include <cstdio>
#include <cmath>
#include <cstring>
#include <climits>
#include <cstring>

using namespace std;

#define  CI( x ) scanf( "%d", &x )

#define VI vector<int>
#define VVI vector<VI >
#define VS vector<string>
#define VC vector<char>
#define VVC vector<VC >
#define VB vector<bool>
#define VVB vector<VB >
#define PAIR pair<int,int>
#define VP vector<PAIR >
#define fo(i,st,ed) for(int i = st; i < ed ; ++i)
#define foE(i,st,ed) for(int i = st; i <= ed ; ++i)
#define foit(i, x) for (typeof((x).begin()) i = (x).begin(); i != (x).end(); i++)
#define bip system("pause")
#define mk make_pair
#define f first
#define s second
#define pb push_back
#define SZ(X) (int)(X).size()
#define LN(X) (int)(X).length()
#define Int long long
#define IO ifstream cin(".in") ; ofstream cout(".out");

int X;
int rem[ 50011 ];
inline int gcd(int a, int b) {
    while(b) {
        a%=b;
        swap(a,b);
    }
    return a;
}
inline int lcm(int a, int b) {
    return (a/gcd(a,b))*b;
}
inline VI p_fact(int N) {
    VI vt;
    for(int i=2; i*i <=N; ++i ) {
        if( N%i == 0 ) {
            while( N%i == 0 ) {
                N/=i;
            }
            vt.pb(i);
        }
    }
    if(N>1) {
        vt.pb(N);
    }
    return vt;
}

inline int calc(int lo, int hi) {
    VI fact = p_fact(lo);
    int res=0;
    int i,j;
    for( i = 1; i< 1<<SZ(fact) ; ++i ) {
        int bit = __builtin_popcount(i);
        int lcm_ = -1;
        for( j = 0 ; j < SZ(fact) ; ++j ) {
            if( ( i & (1<<j) )!=0 ) {
                if(lcm_==-1)lcm_ = fact[j];
                else {
                    lcm_ = lcm( lcm_,fact[j] ) ;
                }
            }
        }
        if( (bit&1)!=0 ) {
            res+= ( hi/lcm_ - ( lo-1) /lcm_ );
        } else {
            res-= ( hi/lcm_ - ( lo-1) /lcm_ );
        }
    }
return res;
}

inline int doit(int N, int f) {
    int total = 1;
    if( rem[ N ]!=-1 ){
        total = rem[N];
        goto L;
    }
    fo(i,1,N) {
        if(i==1) {
            total+= (N-1)*2;
        } else {
            int x = calc(i,N);
            total+= (N-i+1 - x)*2;
        }
    }
    rem[ N ] = total;
L:
    if(f)
        printf("%d\n",total);
return rem[N];
}

int main() {
    memset(rem, -1 , sizeof(rem) );
    fo(i,0,1000){
        rem[i] = doit(i,0);
    }
    while( ( (scanf("%d",&X)) == 1 ) && ( X!=0 ) ) {
        doit(X,1);
    }

    return 0;
}

